package com.xyy.saas.payment.service.impl;

import com.xyy.saas.payment.dao.mapper.ChannelSwitchInfoMapper;
import com.xyy.saas.payment.dao.model.ChannelSwitchInfo;
import com.xyy.saas.payment.service.ChannelSwitchInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ChannelSwitchInfoServiceImpl implements ChannelSwitchInfoService {

    @Autowired
    private ChannelSwitchInfoMapper channelSwitchInfoMapper;

    @Override
    public List<ChannelSwitchInfo> batchInsert(List<ChannelSwitchInfo> entity) {
        if(entity.isEmpty()) {
            return new ArrayList<>();
        }
        List<ChannelSwitchInfo> result = new ArrayList<>();
        for (ChannelSwitchInfo channelSwitchInfo : entity) {
            int rows = channelSwitchInfoMapper.insert(channelSwitchInfo);
            if(rows > 0) {
                result.add(channelSwitchInfo);
            }
        }
        return result;
    }

    @Override
    public List<ChannelSwitchInfo> queryByParam(ChannelSwitchInfo queryParam) {
        return channelSwitchInfoMapper.queryByParam(queryParam);
    }

    @Override
    public ChannelSwitchInfo queryById(Long id) {
        return channelSwitchInfoMapper.queryById(id);
    }

    @Override
    public int deleteById(String id) {
        return channelSwitchInfoMapper.deleteById(id);
    }

    @Override
    public int batchDelete(List<String> ids) {
        int rows = 0;
        for (String id : ids) {
            rows += channelSwitchInfoMapper.deleteById(id);
        }
        return rows;
    }
}
